<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <title>以管理员运行</title>
    <link rel="icon" href="">
    <link rel="stylesheet" href="../../css/bootstrap.min.css">
  </head>
  <body>
  	<form class="form-inline">
  		<div class="form-group">
		    <label>程序</label>
		    <div class="input-group file-input">
		    	<input id="cmdInput" type="text" class="form-control" list="appList" /><label class="input-group-addon btn btn-primary">浏览...</label>
                <datalist id="appList">
                    <option label="文件管理器" value="nautilus"  />
                    <option label="终端" value="gnome-terminal"  />
                </datalist>
            </div>
		</div>
		<div class="form-group">
		    <label></label>
		    <button id="runBtn" type="button" class="btn btn-primary">运行</button>
        </div>
      </form>
      
    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../js/template-web.js"></script>
    <script type="text/javascript" src="../../js/fileinput.js"></script>
    <script type="text/javascript">
        $("#runBtn").click(function(){
            var cmd=$("#cmdInput").val();
            if(!cmd) return;
            if(cmd.endsWith(".desktop")){
                var fs=require('fs');
                var data=fs.readFileSync(cmd).toString("UTF-8");
                var lines=data.split("\n");
                for(var i=0;i<lines.length;i++){
                    if(lines[i].startsWith("Exec=")){
                        window.top.app.runAsRoot(lines[i].substring(5).replace(/%\w+/g,""));
                        break;
                    }
                }
            }else{
                window.top.app.runAsRoot(cmd);
            }
        });
    </script>
  </body>
</html>
